package com.demo2do.fms.admin.entity.search.supplier;

import java.util.Date;
import java.util.Map;

import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

/**
 *
 * @author Ark
 *
 */
public class ReformSearch implements QueryBuilder {
    
    /** 发起人 */
    private Long creator;

    /** 开始创建时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginAppointTime;

    /** 结束时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endAppointTime;

    /** 约谈供方 */
    private Long originateId;
    
    /** 被约谈供方 */
    private Long recipientId;
    
    /** 是否关闭 */
    private Boolean closed;
    
    private QueryOrder queryOrder;

    private QueryFilter queryFilter;

    /**
     * The default constructor
     */
    public ReformSearch() {
        queryOrder = new QueryOrder("appointTime", "DESC");
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {

        if (queryFilter == null || refresh) {

            queryFilter = new QueryFilter().addEquals("creator", creator)
                                           .addDateTimeBetween("appointTime", beginAppointTime, endAppointTime)
                                           .addEquals("recipient.id", recipientId)
                                           .addEquals("closed", closed);
        }
        
        return queryFilter;
        
    }
    
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return queryOrder;
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM Reform" + getPreparedFilter(false).whereSentence() + queryOrder.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
    /**
     * 
     * @return
     */
    public QueryFilter getFilter(){
        return getPreparedFilter(false);
    }

    /**
     * @return the creator
     */
    public Long getCreator() {
        return creator;
    }

    /**
     * @return the beginAppointTime
     */
    public Date getBeginAppointTime() {
        return beginAppointTime;
    }

    /**
     * @return the endAppointTime
     */
    public Date getEndAppointTime() {
        return endAppointTime;
    }

    /**
     * @return the originateId
     */
    public Long getOriginateId() {
        return originateId;
    }

    /**
     * @return the recipientId
     */
    public Long getRecipientId() {
        return recipientId;
    }

    /**
     * @return the closed
     */
    public Boolean getClosed() {
        return closed;
    }

    /**
     * @param creator the creator to set
     */
    public void setCreator(Long creator) {
        this.creator = creator;
    }

    /**
     * @param beginAppointTime the beginAppointTime to set
     */
    public void setBeginAppointTime(Date beginAppointTime) {
        this.beginAppointTime = beginAppointTime;
    }

    /**
     * @param endAppointTime the endAppointTime to set
     */
    public void setEndAppointTime(Date endAppointTime) {
        this.endAppointTime = endAppointTime;
    }

    /**
     * @param originateId the originateId to set
     */
    public void setOriginateId(Long originateId) {
        this.originateId = originateId;
    }

    /**
     * @param recipientId the recipientId to set
     */
    public void setRecipientId(Long recipientId) {
        this.recipientId = recipientId;
    }

    /**
     * @param closed the closed to set
     */
    public void setClosed(Boolean closed) {
        this.closed = closed;
    }
    
}